package main

import (
	"fmt"
	"net"
	"time"
)

func main() {
	fmt.Println("client start")
	time.Sleep(1 * time.Second)

	// 1、直接连接远程服务器，得到一个连接
	conn, err := net.Dial("tcp", "127.0.0.1:8999")
	if err != nil {
		fmt.Println("client dial err:", err)
		return
	}

	for {
		binaryMsg := []byte("zinx 0.6 client test message")
		if _, err := conn.Write(binaryMsg); err != nil {
			fmt.Println("client conn write err:", err)
			return
		}

		buf := make([]byte, 1024)
		// 调用 read 从链接中读数据
		n, err := conn.Read(buf)
		if err != nil {
			fmt.Println("client read err:", err)
		} else {
			fmt.Printf("client call back : %s, cnt = %d\n:", buf, n)
		}

		// CPU阻塞， 间隔一秒写一次
		time.Sleep(1 * time.Second)
	}

}
